package com.lumeng.spring.orm.dao;

import com.lumeng.spring.orm.Condition;
import com.lumeng.spring.orm.Order;
import com.lumeng.spring.orm.Pager;
import com.lumeng.spring.orm.PagerRecords;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;

import javax.persistence.EntityManager;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @ClassName: JpaDao
 * @Description: TODO
 * @author CHEN-HF
 * @date 2017年12月14日 上午10:20:10
 * 
 * @param <T>
 * @param <ID>
 */
@NoRepositoryBean
public abstract interface JpaDao<T, ID extends Serializable> extends JpaRepository<T, ID> {
	public abstract List<T> findAll();

	public abstract List<T> findAll(Sort sort);

	public abstract <S extends T> S saveAndFlush(S s);

	public abstract List<T> findAll(Iterable<ID> iterable);

	public abstract <S extends T> List<S> save(Iterable<S> iterable);

	public abstract void flush();

	public abstract void delete(ID id);

	public abstract void delete(String property, String value);

	public abstract void delete(List<ID> ids);

	public abstract void deleteInBatch(Iterable<T> iterable);

	public abstract void deleteAllInBatch();

	@Deprecated
	public abstract T getOne(ID id);

	public abstract T findOne(ID id);

	public abstract T findOneInitialize(ID id, String[] cAttributes);

	public abstract T findOneByProperty(String propertyName, Object value);

	public abstract T findOneByProperties(String[] properties, Object[] values);

	public abstract T findOneByProperty(String propertyName, Object value, String[] cAttributes);

	public abstract boolean exists(ID id);

	public abstract boolean exists(String propertyName, Object value);

	public abstract <S extends T> List<S> findAll(Example<S> example);

	public abstract <S extends T> List<S> findAll(Example<S> example, Sort sort);

	public abstract List<T> findStartByTermOnAOrB(String propertyA, String propertyB, String term);

	public abstract List<T> commonQuery(Collection<Condition> conditions, Collection<Order> orders);

	public abstract PagerRecords findByPager(Pager pager, Collection<Condition> conditions, Collection<Order> orders);
	
	public abstract long count(Collection<Condition> conditions);

	public abstract List<T> findList(String propertyName, Object value);

	public abstract List<T> findList(String[] properties, Object[] values);

	public abstract T findFirstByProperty(String property, Object value);

	public abstract T findFirstByProperties(String[] properties, Object[] values);

	public abstract void update(String propertyName, Object oldValue, Object newValue);

	public abstract String getEntityName();

	public abstract EntityManager getEntityManager();

	public abstract void initializeObjectCollections(Object initializeObject, String[] cAttributes);
}